var mapIds = new Array();
var 准备地图 = 993001000;

function init() {}

function setup(c, a) {
    em.setProperty("state", 1);
    em.setProperty("leader", "true");
    var c = em.newInstance("小游戏_控制之神");
    for (var b = 1; b <= 40; b++) {
        mapIds.push(准备地图 + b * 10);
        var d = c.setInstanceMap(准备地图 + b * 10);
        em.setProperty("state_" + b, 0)
    }
    return c
}

function onPlayerRegistered(b, a) {
    var d = a.getAPI().getNumberFromQuestInfo(18837, "level");
    var c = b.getMapInstance(d);
    a.changeMap(c, c.getPortal(0));
    a.setReviveCount(-100)
}

function onPlayerRevived(b, a) {
    return false
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    var d = Math.round((a - 993001000) / 10);
    if (d == 8) {
        c.schedule("level" + d + "_stone", 0)
    } else {
        if (d == 9) {
            c.schedule("level" + d + "_platform", 0);
            em.setProperty("level" + d + "_switch", 0)
        } else {
            if (d == 10) {
                c.schedule("level" + d + "_platform", 0)
            } else {
                if (d == 12) {
                    c.schedule("level" + d + "_stone", 0)
                } else {
                    if (d == 14) {
                        c.schedule("level" + d + "_platform", 0)
                    } else {
                        if (d == 17) {
                            c.schedule("level" + d + "_stone", 0)
                        } else {
                            if (d == 18) {
                                em.setProperty("level" + d + "_count", 0);
                                em.setProperty("level" + d + "_switch", -1)
                            } else {
                                if (d == 32) {
                                    c.schedule("level" + d + "_platform", 0);
                                    em.setProperty("level" + d + "_switch", 0)
                                } else {
                                    if (d == 34) {
                                        c.schedule("level" + d + "_stone", 0)
                                    } else {
                                        if (d == 36) {
                                            c.schedule("level" + d + "_platform", 0);
                                            em.setProperty("level" + d + "_switch", 0)
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true)
    })
}

function onMonsterKilled(a, b) {
    return 1
}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}
var setupTask;

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图);
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b)
}

function level8_stone(b) {
    var c = 8;
    var a = 993001000 + c * 10;
    if (em.getPlayersInMap(a).size() == 0) {
        return
    }
    em.getMapFactoryMap(a).obstacleFall(6, 4, 1);
    b.schedule("level" + c + "_stone", 5000)
}

function level9_platform(c) {
    var h = 9;
    var b = 993001000 + h * 10;
    if (em.getPlayersInMap(b).size() == 0) {
        return
    }
    var g = [
        [
            [-2912, -400],
            [-2912, -128]
        ],
        [
            [-305, -531],
            [-305, -220]
        ]
    ];
    var e = [
        [0, 5],
        [0, 5]
    ];
    var f = parseInt(em.getProperty("level" + h + "_switch"));
    var d = (f + 1) % 2;
    for (var a = 0; a <= 1; a++) {
        em.getMapFactoryMap(b).dynamicObjMove(g[a][f][0], g[a][f][1], g[a][d][0], g[a][d][1], g[a][f][0], g[a][f][1], 1, Math.pow(-1, f) * e[a][0], Math.pow(-1, f) * e[a][1], "updown" + a)
    }
    em.setProperty("level" + h + "_switch", d);
    c.schedule("level" + h + "_platform", 2000)
}

function level32_platform(c) {
    var h = 32;
    var b = 993001000 + h * 10;
    if (em.getPlayersInMap(b).size() == 0) {
        return
    }
    var g = [
        [
            [-3084, -304],
            [-3084, 166]
        ],
        [
            [-2427, -304],
            [-2427, 166]
        ],
        [
            [-2165, -304],
            [-2165, 166]
        ]
    ];
    var e = [
        [0, 6],
        [0, 5],
        [0, 5]
    ];
    var f = parseInt(em.getProperty("level" + h + "_switch"));
    var d = (f + 1) % 2;
    for (var a = 0; a <= 2; a++) {
        em.getMapFactoryMap(b).dynamicObjMove(g[a][f][0], g[a][f][1], g[a][d][0], g[a][d][1], g[a][f][0], g[a][f][1], 1, Math.pow(-1, f) * e[a][0], Math.pow(-1, f) * e[a][1], "updown" + (a + 1))
    }
    em.setProperty("level" + h + "_switch", d);
    c.schedule("level" + h + "_platform", 3000)
}

function level36_platform(c) {
    var h = 36;
    var b = 993001000 + h * 10;
    if (em.getPlayersInMap(b).size() == 0) {
        return
    }
    var g = [
        [
            [-3156, -480],
            [-3156, 227]
        ],
        [
            [-2156, -480],
            [-2156, 227]
        ]
    ];
    var e = [
        [0, 7],
        [0, 7]
    ];
    var f = parseInt(em.getProperty("level" + h + "_switch"));
    var d = (f + 1) % 2;
    for (var a = 0; a <= 1; a++) {
        em.getMapFactoryMap(b).dynamicObjMove(g[a][f][0], g[a][f][1], g[a][d][0], g[a][d][1], g[a][f][0], g[a][f][1], 1, Math.pow(-1, f) * e[a][0], Math.pow(-1, f) * e[a][1], "updown" + (a + 1))
    }
    em.setProperty("level" + h + "_switch", d);
    c.schedule("level" + h + "_platform", 5000)
}

function level12_stone(b) {
    var c = 12;
    var a = 993001000 + c * 10;
    if (em.getPlayersInMap(a).size() == 0) {
        return
    }
    em.getMapFactoryMap(a).obstacleFall(6, 4, 1);
    b.schedule("level" + c + "_stone", 5000)
}

function level17_stone(b) {
    var c = 17;
    var a = 993001000 + c * 10;
    if (em.getPlayersInMap(a).size() == 0) {
        return
    }
    em.getMapFactoryMap(a).obstacleFall(6, 4, 1);
    b.schedule("level" + c + "_stone", 5000)
}

function level34_stone(b) {
    var c = 34;
    var a = 993001000 + c * 10;
    if (em.getPlayersInMap(a).size() == 0) {
        return
    }
    em.getMapFactoryMap(a).obstacleFall(6, 4, 1);
    b.schedule("level" + c + "_stone", 5000)
};